home *** CD-ROM | disk | FTP | other *** search
/ United Public Domain Gold 2 / United Public Domain Gold 2.iso / utilities / pu083.dms / pu083.adf / Morse / MORSE1.BAS < prev    next >
BASIC Source File  |  1989-06-09  |  5KB  |  128 lines

  1. 10    ' Morse Code Practice Program. Elwood Downey, WB0OEW, August, 1983.
  2. 20    ' Written for the IBM PC in Microsoft Basica, V1.1, for PC-DOS V1.1.
  3. 30    ' This program may be freely used, traded or copied but the author's
  4. 40    ' name and this stipulation shall remain as comments and the program
  5. 50    ' shall never be sold for profit.
  6. 60    ' Ported to and modified for the AMIGA by W1JT 8-9-88 .
  7.    
  8. 70    CLS
  9.  
  10. 90    '
  11. 100   ' select input source: either from a file, the keyboard or random.
  12. 101 PRINT:PRINT "   ALL entries are to be in LOWER case letters":PRINT
  13. 102 PRINT"       ENTER '!' TO START."
  14. 103 ZZZ$=INKEY$:IF ZZZ$="!" THEN 104 ELSE 103
  15. 104 CLS
  16. PRINT "MORSE1.BAS CODE PRACTICE-AMIGA PORT BY W1JT, 8-9-88 "
  17. 110   INPUT "file name? (or `random' or `kybd:') ",F$
  18. 120   IF F$="random" THEN RANFILE=1 ELSE RANFILE=0
  19. 130   IF RANFILE=1 THEN RANDOMIZE VAL(RIGHT$(TIME$,2)): NCHRS=0: NGRPS=0
  20. 140   IF RANFILE=0 THEN OPEN F$ FOR INPUT AS #1
  21. 150   '
  22. 160   ' select speed
  23. 170   INPUT "wpm? ", WPM
  24. 180   '
  25. 190   ' initialize code strings
  26. 200   ' to add more characters, such as apostrophe, increase numcodes,
  27. 210   ' add code string and character at end of current lists and add case
  28. 220   ' to main loop, below.
  29. 230   NUMCODES = 41  ' . , / ? - plus 26 + 10
  30. 240   DIM CODES$(NUMCODES-1)
  31. 250   DIM CHARS$(NUMCODES-1)
  32. 260   FOR I=0 TO NUMCODES-1
  33. 270     READ CODES$(I)
  34. 280   NEXT
  35. 290  FOR I=0 TO NUMCODES-1
  36. 300    READ CHARS$(I)
  37. 310  NEXT
  38. 320  ' code strings. in one-to-one correspondence with characters, below.
  39. 330  DATA ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "...."
  40. 340  DATA "..", ".---", "-.-", ".-..", "--"
  41. 350  DATA "-.", "---", ".--.", "--.-", ".-.", "...", "-"
  42. 360  DATA "..-", "...-", ".--", "-..-", "-.--", "--.."
  43. 370  DATA "-----", ".----", "..---", "...--", "....-", "....."
  44. 380  DATA "-....", "--...", "---..", "----."
  45. 390  DATA ".-.-.-", "--..--", "-..-.", "..--..", "-...-"
  46. 400  ' characters.
  47. 410  DATA "A", "B", "C", "D", "E", "F", "G", "H"
  48. 420  DATA "I", "J", "K", "L", "M"
  49. 430  DATA "N", "O", "P", "Q", "R", "S", "T"             
  50. 440  DATA "U", "V", "W", "X", "Y", "Z"
  51. 450  DATA "0", "1", "2", "3", "4", "5"
  52. 460  DATA "6", "7", "8", "9"
  53. 470  DATA ".", ",", "/", "?", "-"
  54.  
  55. 500 CLS
  56. 505 PRINT
  57. 510 PRINT "Change line 620 to raise or lower tone frequency "
  58. 520 PRINT "Restart for slower or faster code."
  59. 530 PRINT "Enter Ctrl-C or <RT-AMIGA><.> to quit and restart."
  60. 540 PRINT
  61.  
  62. 610 ' set defaults, init screen.
  63. 620 F = 600             ' initial tone frequency
  64.  
  65. 640 GOSUB 1120   ' calculate dit, dah and space lengths.
  66. 650 GOSUB 1180   ' display wpm and freq
  67. 660 '
  68. 670 ' define character type checking functions
  69. 680  DEF FNLOWER(C$) = "a"<=C$ AND C$<="z"
  70. 690  DEF FNUPPER(C$) = "A"<=C$ AND C$<="Z"
  71. 700  DEF FNDIGIT(C$) = "0"<=C$ AND C$<="9"
  72. 710 '
  73. 720 ' main loop. read (or generate) each character, sound it and print it.
  74. 730  IF RANFILE THEN GOSUB 1240: GOSUB 900: PRINT CHARS$(MORSE);: GOTO 870
  75. 740  C$ = INPUT$(1,#1)
  76. 750  IF " "=C$ OR C$=CHR$(13) THEN GOSUB 990: GOTO 860
  77. 760  IF "."=C$ THEN MORSE=36: GOTO 850  ' morse <- codes$ array index
  78. 770  IF ","=C$ THEN MORSE=37: GOTO 850
  79. 780  IF "/"=C$ THEN MORSE=38: GOTO 850
  80. 790  IF "?"=C$ THEN MORSE=39: GOTO 850
  81. 800  IF "-"=C$ THEN MORSE=40: GOTO 850
  82. 810  IF FNLOWER(C$) THEN C$ = CHR$(ASC(C$)-32)
  83. 820  IF FNUPPER(C$) THEN MORSE=ASC(C$)-ASC("A"):  GOTO 850
  84. 830  IF FNDIGIT(C$) THEN MORSE=ASC(C$)-ASC("0")+26: GOTO 850
  85. 840  GOTO 870
  86. 850 GOSUB 900
  87. 860 PRINT C$; 
  88. 870 GOTO 730
  89. 880 '
  90. 890 ' sound dit for each ".", dah for each "-" in string codes$(morse)
  91. 900 FOR I=1 TO LEN(CODES$(MORSE))
  92. 910   IF MID$(CODES$(MORSE),I,1) = "." THEN GOSUB 1000 ELSE GOSUB 1010
  93. 920 NEXT
  94. 930 GOSUB 980
  95. 940 RETURN
  96. 950 '
  97. 960 ' produce elemental sounds, or silences.
  98. 970  SOUND F,ELE,0 : RETURN  'ELEMENT SPACE
  99.  
  100. 980 SOUND F,ELE*3,0: RETURN     ' character space, allow for previous trailing
  101. 990 SOUND F,ELE*7,0: RETURN   ' word space, allow for trailing.
  102. 1000 SOUND F,DIT,200: GOSUB 970: RETURN        ' dit
  103. 1010 SOUND F,DAH,200: GOSUB 970: RETURN        ' dah
  104.  
  105. 1110 ' calculate element timings. units are clock ticks, which are at 18.2hz.
  106. 1120 IF WPM<13 THEN CWPM=13 ELSE CWPM=WPM
  107. 1130 DIT = 21.84/CWPM: DAH = 3*DIT
  108. 1140 IF WPM>=13 THEN ELE=DIT ELSE ELE= (43.68 - 1.68 * WPM) / WPM
  109. 1150 RETURN
  110. 1160 '
  111. 1170 ' display current speed and frequency. return cursor where it was.
  112. 1180 COL=POS(0): ROW=CSRLIN: LOCATE 1,60
  113. 1190 PRINT " wpm: "; WPM: LOCATE 2,60: PRINT "freq: "; F; "     "
  114. 1200 'LOCATE 2,5: PRINT WPM; "   "
  115. 1210 LOCATE ROW,COL
  116. 1220 RETURN
  117. 1230 '
  118. 1240 ' set MORSE to random value from 0 up to numcodes to select random char.
  119. 1250 ' force a space character after every fifth time we are called
  120. 1260 ' and a newline before every 13 groups.
  121. 1270 IF NCHRS=5 THEN PRINT " ";: GOSUB 990: NCHRS=0: NGRPS=NGRPS+1
  122. 1280 IF NCHRS=0 AND NGRPS=13 THEN PRINT: NGRPS=0
  123. 1290 MORSE = INT(RND*NUMCODES)
  124. 1300 NCHRS=NCHRS+1: RETURN
  125.  
  126.  
  127.  
  128.